package com.yangdage.controller;

import com.alibaba.fastjson.JSONObject;
import com.yangdage.annonations.ServiceTokenRequired;
import com.yangdage.model.TUser;
import com.yangdage.model.TUserExample;
import com.yangdage.service.TUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@EnableAsync
@RestController
@RequestMapping("/user")
public class UserController {
    Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    TUserService userService;


    @RequestMapping("/getUser")
    @ResponseBody
    @ServiceTokenRequired
    public String getUser() {
        return JSONObject.toJSON(userService.selectByExample(new TUserExample())).toString();
    }

    @RequestMapping("/getUserAsync")
    @ResponseBody
    public List<TUser> getUserAsync() {
        List<TUser>  users =  userService.selectByExampleAsync(new TUserExample());
        logger.info(new Date()+"异步执行结束");
        return  users;
    }


}
